<?php

/**
 * Users Controller
 *
 * PHP 5
 *
 * Licensed under The MIT License
 * Redistributions of files must retain the below copyright notice.
 *
 * @author     Yusuf Abdulla Shunan <shunan@maldicore.com>
 * @copyright  Copyright 2012, Maldicore Group Pvt Ltd. (http://maldicore.com)
 * @license    MIT License (http://www.opensource.org/licenses/mit-license.php)
 * @since      CakePHP(tm) v 2.1.1
 */
App::uses('AdminAppController', 'Admin.Controller');
App::uses('AppController', 'Controller');

class CmspagesController extends AdminAppController {

    var $helpers = array('Form');

    function index() {
        $this->loadModel('Cmspages');
        $this->paginate = array(
            'limit' => 25,
            'order' => array('Cmspages.id' => 'desc')
        );

        // we are using the 'Admin' model
        $rows = $this->paginate('Cmspages');

        // pass the value to our view.ctp
        $this->set('rows', $rows);
    }

    function edit($id = null) {
        if (!$id) {
            throw new NotFoundException(__('Invalid post'));
        }
        $this->loadModel('Cmspages');
        
        $post = $this->Cmspages->findById($id);
        if (!$post) {
            throw new NotFoundException(__('Invalid post'));
        }

        if ($this->request->is(array('post', 'put'))) {
            $this->Cmspages->id = $id;            

            if ($this->Cmspages->save($this->request->data)) {
                $this->Session->setFlash('Page has been updated.!', 'default', array(), 'good');
                return $this->redirect(array('action' => 'index'));
            }
            $this->Session->setFlash('Unable to update page.!', 'default', array(), 'bad');
        }

        if (!$this->request->data) {
            $this->request->data = $post;
        }
    }
    
}
